package com.esun.cheetah.biz.news;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;

import com.esun.cheetah.config.Key;
import com.esun.cheetah.model.news.NewsHeadBean;
import com.esun.cheetah.network.AbsInferiorityCommunicater;
import com.esun.util.log.EDebug;

public class NewsHeadCommunicater extends AbsInferiorityCommunicater {

	private ArrayList<NewsHeadBean> List;
	private String colid;
	private int pageno;

	public NewsHeadCommunicater(Handler handler, String colid, int pageno) {
		super(handler);
		List = new ArrayList<NewsHeadBean>();
		this.colid = colid;
		this.pageno = pageno;

	}

	@Override
	public HashMap<String, String> comHashMap() {
		HashMap<String, String> hmJson = new HashMap<String, String>();

		hmJson.put(Key.KEY_ID, "10036");
		hmJson.put("pagesize", "5");// 每页显示条数
		hmJson.put("page", String.valueOf(pageno));// 页码
		hmJson.put("colid", colid);// colid新闻类型:专家推荐2，足彩动态7，篮彩动态18，首页新闻40

		return hmJson;

	}

	/**
	 * @return
	 * @throws JSONException
	 * @Title: getJsonContent
	 * @Description: 解析json
	 * @param
	 * @return Object
	 * @throws
	 */
	@Override
	public void getJsonContent(String serverRes) throws JSONException {

		JSONObject jsonObject = new JSONObject(serverRes);
		JSONArray artr = jsonObject.getJSONArray(Key.KEY_DATA);
		for (int i = 0; i < artr.length(); i++) {
			JSONObject localJs = artr.optJSONObject(i);
			if (localJs != null) {
				NewsHeadBean ListBean = new NewsHeadBean();
				EDebug.o("从新开始解析===》 ");
				ListBean.id = localJs.getString("id"); //
				EDebug.o("新闻id--->" + ListBean.id);
				ListBean.bigtitle = localJs.getString("bigtitle"); //
				EDebug.o("标题--->" + ListBean.bigtitle);
				ListBean.oprtime = localJs.getString("oprtime"); //
				EDebug.o("新闻发表时间--->" + ListBean.oprtime);
				ListBean.status = localJs.getString("status"); //
        EDebug.o("活动状态--->" + ListBean.status);
				List.add(ListBean);

			}
		}
	}

	public ArrayList<NewsHeadBean> getLotteryList() {
		return this.List;
	}

	public void setLotteryList(ArrayList<NewsHeadBean> lotteryList) {
		this.List = lotteryList;
	}
}